package com.css.fxfzdpzs.modules.fxpg.controller;

import com.css.fxfzdpzs.base.response.RestResponse;
import com.css.fxfzdpzs.modules.fxpg.entity.*;
import com.css.fxfzdpzs.modules.fxpg.service.FxpgService;
import com.css.fxfzdpzs.modules.fxpg.vo.LevelProVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 全国风险区划图
 */
@Api(tags = "全国风险区划图")
@Slf4j
@RestController
@RequestMapping("/fxpg")
public class FxpgController {
    @Autowired
    private FxpgService fxpgService;

    //一级表单
    //全国活动断层数据
    @ApiOperation(notes = "全国活动断层数据", value = "全国活动断层数据")
    @GetMapping("/getActivityFaultData")
    public RestResponse getActivityFaultData() {
        RestResponse restResponse = null;
        try {
            ActivityFaultData data = fxpgService.getActivityFaultData();
            restResponse = RestResponse.succeed(data);
        } catch (Exception e) {
            String errormessage = "查询全国活动断层数据失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国危险性等级区划
    @GetMapping("/getNationwideRiskData")
    public RestResponse getNationwideRiskData() {
        RestResponse restResponse = null;
        try {
            Double[] doubles = fxpgService.getNationwideRiskData();
            restResponse = RestResponse.succeed(doubles);
        } catch (Exception e) {
            String errormessage = "查询全国危险性等级区划失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国承灾体数据
    @GetMapping("/getBodyData")
    public RestResponse getBodyData() {
        RestResponse restResponse = null;
        try {
            Map<String, Object> map = fxpgService.getBodyData();
            restResponse = RestResponse.succeed(map);
        } catch (Exception e) {
            String errormessage = "查询全国承灾体数据失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国承灾体数据
    @GetMapping("/getDisasterBodyData")
    public RestResponse getDisasterBodyData() {
        RestResponse restResponse = null;
        try {
            Map<String, List<DisasterData>> map = fxpgService.getDisasterBodyData();
            restResponse = RestResponse.succeed(map);
        } catch (Exception e) {
            String errormessage = "查询全国承灾体数据失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国重点目标数据
    @GetMapping("/getKeynoteTargetData")
    public RestResponse getKeynoteTargetData() {
        RestResponse restResponse = null;
        try {
            List<KeynoteTargetData> list = fxpgService.getKeynoteTargetData();
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询全国重点目标数据失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    //全国风险评估数据
    @GetMapping("/getRiskEstimateData")
    public RestResponse getRiskEstimateData(@RequestParam(value = "estimate0bj",required = false)String estimate0bj,
                                            @RequestParam(value ="condition",required = false)String condition,
                                            @RequestParam(value ="assessType",required = false)String assessType) {
        RestResponse restResponse = null;
        try {
            Map<String, Object> map = fxpgService.getRiskEstimateData(estimate0bj,condition,assessType);
            restResponse = RestResponse.succeed(map);
        } catch (Exception e) {
            String errormessage = "查询全国风险评估数据失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国地震地质灾害概况

    //全国风险区划数据
    @GetMapping("/getRiskPlanData")
    public RestResponse getRiskPlanData(@RequestParam(value = "estimate0bj",required = false)String estimate0bj,
                                        @RequestParam(value ="condition",required = false)String condition,
                                        @RequestParam(value ="assessType",required = false)String assessType) {
        RestResponse restResponse = null;
        try {
            if(StringUtils.isBlank(estimate0bj)){
                estimate0bj = "1";
            }
            if(StringUtils.isBlank(condition)){
                if("1".equals(assessType)){
                    condition = "VI度";
                }
            }
            if(StringUtils.isBlank(assessType)){
                assessType = "1";
            }
            List<LevelProVo> vos = fxpgService.getRiskPlanData(assessType,estimate0bj,condition);
            restResponse = RestResponse.succeed(vos);
        } catch (Exception e) {
            String errormessage = "查询全国风险区划数据失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    //风险区划访问量统计
    @GetMapping("/getVisitNum")
    public RestResponse getVisitNum(@RequestParam String system) {
        RestResponse restResponse = null;
        try {

            Map<String, Object> map = fxpgService.getVisitNum(system);
            restResponse = RestResponse.succeed(map);
        } catch (Exception e) {
            String errormessage = "查询风险区划访问量统计失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国地震地质灾害概况
    @GetMapping("/getDisasterOverview")
    public RestResponse getDisasterOverview() {
        RestResponse restResponse = null;
        try {
            String system = "0";
            List<DisasterOverview> list = fxpgService.getDisasterOverview(system);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询全国地震地质灾害概况失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //全国地震地质灾害概况
    @GetMapping("/getMapRiskData")
    public RestResponse getMapRiskData(@RequestParam String type) {
        RestResponse restResponse = null;
        try {
            List<RiskMapData> list = fxpgService.getMapRiskData(type);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询全国地震地质灾害概况失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }
}
